fix: proto message unable to bind path param #3303
Open
+23
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description (what this PR does / why we need it):
proto-gen-go-http 在调用时使用binding.EncodeURL 进行参数绑定,path中使用snakeCase命名方法会导致参数绑定失败,使用camelCase则正常。
proto 的命名规范为snakeCase。
例如
Which issue(s) this PR fixes (resolves / be part of):
原因:
form.EncodeValues读取字段的值如果是proto类型的使用的是protobuf中的json字段命名camelCase。
后续匹配path参数(命名规则为snakeCase)则无法匹配到。
解决方法:
绑定参数时候判断是否为proto 消息,如果是proto消息并且未匹配到参数直接修改key为camelCase 进行匹配